/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package admin.matrices;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import DBMS.DataBaseManager;
import admin.permisos.PermisosManager;
import clases.Matriz;
import clases.Usuario;

/**
 *
 * @author andreth
 */
public class EliminarMatriz extends DispatchAction {

    /* forward name="success" path="" */
    private static final String SUCCESS = "success";
    private static final String FAILURE = "failure";
    private static final String name = "Eliminar Matriz";


    /*   public ActionForward populate(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response)
    throws Exception {
    return mapping.findForward(SUCCESS);
    }
     */
    public ActionForward delete(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
//        Usuario usr = (Usuario) request.getSession().getAttribute("logueado");
//        DataBaseManager dbms = DataBaseManager.getInstance();
//        if (!PermisosManager.validar(this.name, dbms.consultarPermisoAccion(name), usr.getPermiso())) {
//            System.out.println("No tiene permiso");
//            return mapping.findForward(FAILURE);
//        }
        DataBaseManager dbms = DataBaseManager.getInstance();
//        //Se obtiene instancia de la base de datos
//        DataBaseManager dbms = DataBaseManager.getInstance();

        Matriz porEliminar = (Matriz) form;
        boolean eliminado = dbms.eliminarMatriz(porEliminar);
        /*
         * Si se eliminó la matriz, success
         */
        request.setAttribute("matrices", DataBaseManager.getInstance().consultarMatrices());
        if (eliminado) {
            porEliminar.setMensajeOK("Matriz Eliminada satisfactoriamente");

            return mapping.findForward(SUCCESS);
        }
        // De lo contrario fallo.
        porEliminar.setMensaje("No se pudo eliminar la Matriz");
        return mapping.findForward(FAILURE);
    }
}
